home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2003 June / macformat-130.iso / pc / Shareware_Freeware (OS X) / Internet / soybo-1.0.1 / macosx_components / Sample Soyvices / iPhoto / iPhoto.php next >
Encoding:
PHP Script  |  2003-03-27  |  3.2 KB  |  116 lines

  1. <?php
  2.  
  3. /* Copyright (C) 2003 Adam Tow
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2 of the License, or
  8.    (at your option) any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  18.    
  19.  
  20. function RunWithParams($methodName, $params)
  21. {    
  22.     global $_CONF;
  23.     
  24.     if(class_exists("SCPT_Script_Handler")) {
  25.         switch($methodName)
  26.         {        
  27.             case "new":
  28.                 return New_Album($params);
  29.                     
  30.             case "upload":
  31.                 return Upload($params);
  32.             
  33.             case "action":
  34.                 if($params["action"]) {
  35.                     if($params["selected"] && is_array($params["selected"]) && count($params["selected"]) > 0) {
  36.                         $methodName = $params["action"];
  37.                         
  38.                         $scriptHandler = new SCPT_Script_Handler;
  39.                         $scriptPath = $params["path_service"] . "scripts/iPhoto.scpt";
  40.                     
  41.                         return $scriptHandler->RunScript($scriptPath, $methodName, $params);
  42.                     } else {
  43.                         return ScriptErrorResponse("", $params["locale"]["errNoSelectedImages"]);
  44.                     }
  45.                 } else {
  46.                     return ScriptErrorResponse("", $params["locale"]["errInvalidParameters"]);
  47.                 }
  48.                 break;
  49.             
  50.             default:
  51.                 $scriptHandler = new SCPT_Script_Handler;
  52.                 $scriptPath = $params["path_service"] . "scripts/iPhoto.scpt";
  53.                 
  54.                 return $scriptHandler->RunScript($scriptPath, $methodName, $params);
  55.                 break;
  56.         
  57.         }
  58.     } else {
  59.         return ScriptErrorResponse("", $_CONF["locale"]->GetString("errScriptHandlerNotFound"));
  60.     }
  61. }
  62.  
  63.  
  64.  
  65. function New_Album($params)
  66. {
  67.     $scriptHandler = new SCPT_Script_Handler;
  68.  
  69.         // Make sure that an album with this name doesn't already exist
  70.         
  71.     $albumName = $params["album"];
  72.     $cmd = "tell application \"iPhoto\" to return count of (every album whose name is \"$albumName\")";
  73.     $pipe = popen("osascript -e '$cmd'", "r");
  74.     while($s = fgets($pipe, 1024)) $result .= $s;
  75.     pclose($pipe);
  76.     
  77.     if($result != 0)
  78.         return ScriptErrorResponse("", $params["locale"]["errAlbumNameInUse"]);
  79.     
  80.         // Places the file uploads into a temp directory. We'll add them to the iPhoto Library
  81.     
  82.     
  83. }
  84.  
  85.  
  86.  
  87. function Upload($params)
  88. {
  89.     for($i = 1; $i <= 5; $i++) {
  90.         $filename = "img" . $i;
  91.         
  92.         if ($_FILES[$filename] != "" && !$_FILES[$filename]["error"]) {
  93.             $newFilename = "/tmp/" . $_FILES[$filename]['name'];
  94.             
  95.             if($newFilename != "/tmp/") {
  96.                 copy($_FILES[$filename]['tmp_name'], $newFilename) or die("Couldn't copy the file!");  
  97.             
  98.                     // Set the filename
  99.                 
  100.                 $params["filename"] = $newFilename;
  101.                         
  102.                     // Call the iPhoto AppleScript, which will handle importing the files
  103.             
  104.                 $scriptHandler = new SCPT_Script_Handler;
  105.                 $scriptPath = $params["path_service"] . "scripts/iPhoto.scpt";
  106.                 
  107.                 $result = $scriptHandler->RunScript($scriptPath, "import", $params);
  108.             }
  109.         }
  110.     }
  111.     
  112.     return $result;
  113. }
  114.  
  115.  
  116. ?>